package sistem.management.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class AdaugaMaterial extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			System.out.println("AdaugaMaterial req params: \ndenumire:" + req.getParameter("denumire") + "\nemaildoctor:" + req.getParameter("emaildoctor")
					+ "\ncantitate:" + req.getParameter("cantitate"));
			DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
			Key materialKey = KeyFactory.createKey("material", req.getParameter("denumire"));
			Entity material = new Entity(materialKey);

			material.setProperty("emaildoctor", req.getParameter("emaildoctor"));
			material.setProperty("denumire", req.getParameter("denumire"));
			material.setProperty("cantitate", req.getParameter("cantitate"));

			datastore.put(material);

			resp.getWriter().write("succes");
		} catch (Exception e) {
			e.printStackTrace();
			resp.getWriter().write("fail");
		}
	}
}
